public override int GetHashCode() { int hash = 3; unchecked { hash = (hash * 7) + DefinedIn.GetHashCode(); hash = (hash * 7) + NamedRanges.GetHashCode(); } return(hash); }
public override bool Equals(object obj) { var other = obj as Context; if (ReferenceEquals(other, this)) { return(true); } if (ReferenceEquals(other, null)) { return(false); } return(DefinedIn.Equals(other.DefinedIn) && NamedRanges.Equals(other.NamedRanges)); }
public void GenerateObjcType(string directory, string[] frameworks) { if (IsModel) { // We don't generate header files for protocols. return; } string hFilePath = Path.Combine(directory, ObjCName + ".h"); string mFilePath = Path.Combine(directory, ObjCName + ".m"); using (var sw = File.CreateText(hFilePath)) { sw.WriteLine(modificationWarning); sw.WriteLine(); foreach (var framework in frameworks) { sw.WriteLine("#import <{0}/{0}.h>", framework); } sw.WriteLine(); foreach (var reference in UserTypeReferences) { sw.WriteLine("#import \"{0}.h\"", reference); } sw.WriteLine(); if (BaseObjCType == null && BaseCliType != null && !BaseIsModel) { throw new ObjectiveCGenerationException(string.Format( "Could not generate class '{0}' as its base type '{1}' could not be resolved to Objective-C.\n\n" + "Hint: Try adding [Register (\"{2}\")] to the class definition for {1}.", CliName, BaseCliType, GetSuggestedRegisterName(BaseCliType)), this); } var baseType = BaseIsModel ? "NSObject" : BaseObjCType; sw.WriteLine("@interface {0} : {1} {{", ObjCName, baseType); foreach (var outlet in Outlets) { sw.WriteLine("\t{0} *_{1};", AsId(outlet.ObjCType), outlet.ObjCName); } sw.WriteLine("}"); sw.WriteLine(); foreach (var outlet in Outlets) { var type = AsId(outlet.ObjCType); if (string.IsNullOrEmpty(type)) { throw new ObjectiveCGenerationException(string.Format( "Could not generate outlet '{0}' in class '{1}' as its type '{2}' could not be resolved to Objective-C.\n\n" + "Hint: Try adding [Register (\"{3}\")] to the class definition for {2}.", outlet.CliName, this.CliName, outlet.CliType, GetSuggestedRegisterName(outlet.CliType)), this); } sw.WriteLine("@property (nonatomic, retain) IBOutlet {0} *{1};", type, outlet.ObjCName); sw.WriteLine(); } foreach (var action in Actions) { WriteActionSignature(action, sw); sw.WriteLine(";"); sw.WriteLine(); } sw.WriteLine("@end"); } using (var sw = File.CreateText(mFilePath)) { sw.WriteLine(modificationWarning); sw.WriteLine(); sw.WriteLine("#import \"{0}.h\"", ObjCName); sw.WriteLine(); sw.WriteLine("@implementation {0}", ObjCName); sw.WriteLine(); bool hasOutlet = false; foreach (var outlet in Outlets) { sw.WriteLine("@synthesize {0} = _{0};", outlet.ObjCName); hasOutlet = true; } if (hasOutlet) { sw.WriteLine(); } foreach (var action in Actions) { if (action.Parameters.Any(p => p.ObjCType == null)) { continue; } WriteActionSignature(action, sw); sw.WriteLine(" {"); sw.WriteLine("}"); sw.WriteLine(); } sw.WriteLine("@end"); } var lastSourceUpdateTime = DefinedIn.Max(f => File.GetLastWriteTime(f)); File.SetLastWriteTime(hFilePath, lastSourceUpdateTime); File.SetLastWriteTime(mFilePath, lastSourceUpdateTime); }